<template>
	<view class="info">
		<view class="block">
			<view class="content">
				<view class="my">
					我的钱包余额：{{my_amount}}元
				</view>
			</view>
		</view>
		<view class="block">
			<view class="title">
				充值金额
			</view>
			<view class="content">
				<view class="amount">
					<view class="list">
						<view v-for="(item,index) in recharge_list" :key="index" :class="item.id==id?'on_box':'box'" @tap="recharfe_click" :data-id="item.id">
							<view>
								{{item.money}}元
							</view>
							<view class="selling">
								售价{{item.selling_price}}
							</view>
						</view>
					</view>
					
					<view class="num">
						<view class="text">
							自定义充值金额
						</view>
						<view class="input">
							<input type="number" v-model="amount" @input="in_amount" />
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="block">
			<view class="title">
				选择支付方式
			</view>
			<view class="content">
				<view class="pay-list">
					<view class="row">
							<tui-icon name="wechat" color="#1afa29" :size="32"></tui-icon>
							<view class="center">
								微信支付
							</view>
							<view class="right">
								<radio :checked="true" color="#f06c7a" />
							</view>
					</view>
				</view>
			</view>
		</view>
		<view class="pay">
			<view class="btn" @tap="doDeposit">立即充值</view>
		</view>
	</view>
</template>

<script>
	import tuiIcon from "@/components/icon/icon.vue"
	import Recharge from './recharge-model.js'
	var recharge = new Recharge(); 
	export default {
		components: {
			tuiIcon
		
		},
		data() {
			return {
				amount:'',
				recharge_list:[],
				id:0,
				my_amount:0,
				wechat_pay_status:0
			}
		},
		onLoad(){
			var that = this;
			that.get_recharge_list();
			that.my();
			that.config_info();
		},
		methods: {
			//获取充值模板列表
			get_recharge_list(){
				var that = this;
				recharge.get_recharge_list((res)=>{
					if(res.code==8888){
						that.recharge_list = res.data;
					}
				})
			},
			//我的信息
			my(){
				var that = this;
				recharge.my((res)=>{
					if(res.code == 8888){
						that.my_amount = res.data.amount;
					}
				})
			},
			//获取商城配置信息
			config_info(){
				var that = this;
				recharge.config_info((res)=>{
					if(res.code == 8888){
						that.wechat_pay_status = res.data.wechat_pay_status;
					}
				})
			},
			//选择充值模板
			recharfe_click(e){
				var that = this;
				that.id = recharge.get_data_set(e,'id');
				if(that.id>0){
					that.amount = '';
				}
			},
			//金额输入时
			in_amount(e){
				var that = this;
				that.amount = e.detail.value;
				if(e.detail.value > 0){
					that.id = 0;
				} 
			},
			//立即充值
			doDeposit(){
				var that = this;
				if(that.wechat_pay_status == 0){
					recharge.show_tips({title:'微信支付未开通！'});
				}
			}
		}
	}
</script>

<style>
	@import url("recharge.css");
</style>
